package com.ktwlsoft.archivemanage.domain.business.repositoryService.view;

import com.ktwlsoft.archivemanage.domain.dao.repository.view.ReportCommitedUnitMapper;
import com.ktwlsoft.archivemanage.payload.view.ReportProgress;
import lombok.Getter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Year;
import java.util.ArrayList;
import java.util.List;

@Service
public class AnnualReportDataProfileRepositoryService {

    @Getter
    private final ReportCommitedUnitMapper reportCommitedUnitMapper;

    public AnnualReportDataProfileRepositoryService(ReportCommitedUnitMapper reportCommitedUnitMapper) {
        this.reportCommitedUnitMapper = reportCommitedUnitMapper;
    }

    @Transactional(rollbackFor = Exception.class)
    public List<ReportProgress> getReportProgress(Year year) {
        int reportCount = reportCommitedUnitMapper.getReportedUnitCount(year);
        int totalUnitCount = reportCommitedUnitMapper.getTotalUnitCount(year);
        List<ReportProgress> list = new ArrayList<>();
        list.add(new ReportProgress(reportCount, totalUnitCount));
        return list;
    }
}
